package com.ihmp.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.ihmp.business.CommonUtils;
import com.ihmp.model.User;

public class CheckLoginInterceptor extends HandlerInterceptorAdapter {
	public boolean preHandle(HttpServletRequest request,HttpServletResponse response,Object handler) throws Exception{
		User cur_user = new User();
		cur_user.setUserName("ngantt");
		cur_user.setFullName("Nguyễn Thị Ngân");
		cur_user.setJobTitleId(1);
		cur_user.setHotelId(1);
		request.getSession().setAttribute("user", cur_user);		

		if(!CommonUtils.isLogin(request)) {
			response.sendRedirect(request.getContextPath() + "/credential.html");
			return false;
		}
		return true;
	}
}
